window.onload = function () {
  setInterval("show()", 1000);
  var prev = document.getElementById("prev");
  var next = document.getElementById("next");
  var imgList = document.getElementById("imgList");
  var img = document.getElementsByTagName("img")[2];
  var imgArr = [
    "./img/01.jpg",
    "./img/02.jpg",
    "./img/03.jpg",
    "./img/04.jpg",
    "./img/05.jpg",
    "./img/06.jpg",
    "./img/07.jpg",
    "./img/08.jpg",
    "./img/01.jpg",
  ];
  imgList.style.width = 610 * imgArr.length + "px";
  var index = 0;
  var allA = document.getElementsByClassName("navs");
  allA[index].style.backgroundColor = "#FFF";
  for (var i = 0; i < allA.length; i++) {
    allA[i].num = i;

    allA[i].onclick = function () {
      clearInterval(timer);
      index = this.num;
      //切换图片
      imgList.style.left = -610 * index + "px";
      setA();
      move(imgList, "left", -610 * index, 40, function () {
        //动画执行完毕，开启自动切换
        autoChange();
      });
    };
  }
  autoChange();
  function setA() {
    if (index >= imgArr.length - 1) {
      index = 0;
      imgList.style.left = 0;
    }
    for (var i = 0; i < allA.length; i++) {
      allA[i].style.backgroundColor = "";
    }
    allA[index].style.backgroundColor = "#FFF";
  }
  var timer;
  function autoChange() {
    timer = setInterval(function () {
      index++;
      index %= imgArr.length;
      move(imgList, "left", -610 * index, 20, function () {
        setA();
      });
    }, 2000);
  }
  prev.onclick = function () {
    clearInterval(timer);
    index--;
    if (index < 0) {
      index = imgArr.length - 1;
    }
    img.src = imgArr[index];
    setA();
    move(imgList, "left", -610 * index, 40, function () {
      autoChange();
    });
  };
  next.onclick = function () {
    clearInterval(timer);
    index++;
    if (index > imgArr.length - 1) {
      index = 0;
    }

    img.src = imgArr[index];
    setA();
    move(imgList, "left", -610 * index, 40, function () {
      autoChange();
    });
  };
};
function show() {
  var s1 = "2022-03-26 16:00:00";
  s1 = new Date(s1.replace(/-/g, "/"));
  s2 = new Date();
  //获取得出时间差
  var day = s1.getTime() - s2.getTime();
  var hour = parseInt((day % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60));
  var minute = parseInt((day % (1000 * 60 * 60)) / (1000 * 60));
  var second = parseInt((day / 1000) % 60);
  document.getElementById("time1").innerHTML = hour;
  document.getElementById("time2").innerHTML = minute;
  document.getElementById("time3").innerHTML = second;
}
